//
//  CycBleMessage.h
//  Cycling
//
//  Created by cjg.mini on 2023/3/10.
//

#import <Foundation/Foundation.h>

#define CYC_PROTOCOL_HEADER         0x3A // 协议头
#define CYC_PROTOCOL_FOOTER1        0x0D // 协议尾1
#define CYC_PROTOCOL_FOOTER2        0x0A // 协议尾2

typedef struct {
    uint8_t target;
    uint8_t cmd;
    uint8_t len;
    NSData * _Nullable data;
}__attribute__((packed)) CYC_MessageBody;

NS_ASSUME_NONNULL_BEGIN

@interface CycBleMessage : NSObject

@property (nonatomic, readonly, assign) CYC_MessageBody body;
@property (nonatomic, readonly, strong) NSData *extra;
@property (nonatomic, readonly, strong) NSString *key;

// 初始化消息 -- 组包
- (instancetype)initWithTarget:(uint8_t)target cmd:(uint8_t)cmdID data:(NSData * __nullable)data;

// 生成消息 --- 解包
- (instancetype)initWithData:(NSData * __nullable)data;
@end

NS_ASSUME_NONNULL_END
